$(function () {
    $('.list-header-2').mouseenter(function () {
        var jizhan = $(".list-jizhan")[0];
        jizhan.style.backgroundColor="rgba(0,0,0,0.1)";
	$('.list-jizhan2').stop().slideDown(100);
    });
    $('.list-jizhan2').mouseenter(function () {
        var jizhan = $(".list-jizhan")[0];
        jizhan.style.backgroundColor="rgba(0,0,0,0.1)";
	$('.list-jizhan2').stop().slideDown(100);
    });
    $('.list-jizhan').mouseenter(function () {
        this.style.backgroundColor="rgba(0,0,0,0.1)";
	$('.list-jizhan2').stop().slideDown(100);
    });
    $('.list-jizhan').mouseleave(function () {
        this.style.backgroundColor="#2198E0";
	$('.list-jizhan2').stop().slideUp(300);
    });
    $('.list-header-2').mouseleave(function () {
        var jizhan = $(".list-jizhan")[0];
        jizhan.style.backgroundColor="#2198E0";
	$('.list-jizhan2').stop().slideUp(300);
    });
    $('.list-jizhan2').mouseleave(function () {
	$('.list-jizhan2').stop().slideUp(300);
        var jizhan = $(".list-jizhan")[0];
        jizhan.style.backgroundColor="#2198E0";
    });
    $("#list-bn1").click(function () {
        ProjectName = GetQueryString("ProjectName");
        page = GetQueryString("page");
        if (page == null){page = 1};
	name = ProjectName + '(第' +page + '页)' +'.xls';
	method('tableExcel','name',name);
    });

    var idTmr;
    function getExplorer() {
	var explorer = window.navigator.userAgent;
	//ie
	if (explorer.indexOf("MSIE") >= 0) {
	    return 'ie';
	}
	//firefox
	else if (explorer.indexOf("Firefox") >= 0) {
	    return 'Firefox';
	}
	//Chrome
	else if (explorer.indexOf("Chrome") >= 0) {
	    return 'Chrome';
	}
	//Opera
	else if (explorer.indexOf("Opera") >= 0) {
	    return 'Opera';
	}
  	//Safari
  	else if (explorer.indexOf("Safari") >= 0) {
	    return 'Safari';
	}
    }
    function method(tableid,name,filename) {
	if (getExplorer() == 'ie')
	{
	    var curTb1 = document.getElementById(tableid);//整个表格拷贝到excel中
	    var oXL = new ActiveXObject("Excel.Application");//创建AX对象excel
	    var oWB = oXL.Workbooks.Add();//获取workbook对象
	    var xlsheet = oWB.Worksheets(1);//激活当前sheet
	    var sel = document.body.createTextRange();
	    sel.moveToElementText(curTb1);//把表格中的内容移动到TextRange中
	    sel.select();//全选TextRange中内容
	    sel.execCommand("Copy");//复制TextRange中内容
	    xlsheet.Paste();//粘贴到活动的EXCEL中
	    oXL.Visible = true;//设置excel可见性
	    try {
		var fname = oXL.Application.GetSaveAsFilename("Excel.xls", "Excel Spreadsheets (*.xls), *.xls");
	    } catch(e) {
		print("Nested catch caught" + e);//用于打印当前窗口的内容
	    } finally {
		oWB.SaveAs(fname);
		oWB.Close(savechanges = false);
		oXL.Quit();
		oXL = null;
		//结束excel进程，退出完成
		idTmr = window.setInterval("Cleanup();", 1);
	    }
	}
	else
	{
	    tableToExcel(tableid, name, filename);
	}
    }
    function Cleanup() {
	window.clearInterval(idTmr);
	CollectGarbage();
    }
    var tableToExcel = (function () {
	var uri = 'data:application/vnd.ms-excel;base64,',
	template = '<html><head><meta charset="UTF-8"></head><body><table border="1">{table}</table></body></html>',
	base64 = function(s) {return window.btoa(unescape(encodeURIComponent(s)))},
	format = function(s, c) {
	    return s.replace(/{(\w+)}/g,function(m,p){return c[p];})
	}
	return function(table, name,filename) {
	    if(!table.nodeType) table = document.getElementById(table)
	    var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}
   	    document.getElementById("dlink").href = uri + base64(format(template, ctx))
	    document.getElementById("dlink").download = filename;
	    document.getElementById("dlink").click();
	    //window.location.href = uri + base64(format(template, ctx))
	}
    })()

    //采用正则表达式获取地址栏参数
    function GetQueryString(name) {
        var url = window.location.search;
	var reg = new RegExp("(^|&)"+name+"=([^&]*)(&|$)");
	var result = url.substr(1).match(reg);
        return result ? decodeURIComponent(result[2]): null;
    }

});
